package com.example.ddz.framework.impl;

/**
 * Created by IntelliJ IDEA.
 * User: Marcel Melzig
 * Date: 20.07.11
 * Time: 20:46
 */

import android.media.SoundPool;

import com.example.ddz.framework.ISound;

/**
 * This class defines the instance of an sound object. This is a small sound file with a length of a few seconds.
 */
public class Sound implements ISound
{
    private final int soundId;
    private final SoundPool soundPool;

    /**
     * Initializes an instance of the Sound class.
     *
     * @param soundPool The sound pool.
     * @param soundId   The id of a sound in the sound pool.
     */
    public Sound(SoundPool soundPool, int soundId)
    {
        this.soundId = soundId;
        this.soundPool = soundPool;
    }

    /**
     * Plays a sound with the given volume.
     *
     * @param volume The volume of the sound.
     */
    @Override
    public void Play(float volume)
    {
        soundPool.play(soundId, volume, volume, 0, 0, 1);
    }

    /**
     * Disposes the sound object and releases the resources.
     */
    @Override
    public void Dispose()
    {
        soundPool.unload(soundId);
    }
}
